package org.ethereum.net.eth.message;

import org.ethereum.util.RLP;
import org.ethereum.util.RLPItem;

/**
 * Wrapper around an Ethereum Transactions message on the network
 *
 * @see EthMessageCodes#TRANSACTIONS
 */
public class KPIReportMessage extends EthMessage {

    private String jsonString;

    public KPIReportMessage(byte[] encoded) {
        super(encoded);
//        RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
//        this.jsonString = new String(paramsList.get(0).getRLPData());
        RLPItem item = (RLPItem)RLP.decode2(encoded).get(0);
        this.jsonString = new String(item.getRLPData());
    }

    public KPIReportMessage(String jsonString) {
        this.jsonString = jsonString;
        parsed = true;
    }

    private void encode() {
        this.encoded = RLP.encodeElement(jsonString.getBytes());
    }

    @Override
    public byte[] getEncoded() {
        if (encoded == null) encode();
        return encoded;
    }

    public String getReport() {
    		return jsonString;
    }
    
    @Override
    public EthMessageCodes getCommand() {
        return EthMessageCodes.KPIREPORT;
    }

    @Override
    public Class<?> getAnswerMessage() {
        return null;
    }

    public String toString() {
        return "[" + getCommand().name() + " json: " + jsonString+ "]";
    }
}